<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>day03</title>
</head>

<body>

</body>
<script>
    //1 var let const 三种声明变量区别
    console.log(q)
    var q = 1;
    console.log(q)
    // console.log(s)
    let s = 1
    console.log(s)
    const ln = 98
    console.log(ln)



    // 2解构赋值
    // 按照一定规范提取值，赋值变量
    let arr = [1, 2, 3, 4, 5, 6]
    let [a, , c, d, e, f] = arr
    console.log(a, c, f, d, e)
    // 扩展运算符
    let [h, j, ...g] = arr
    console.log(h, j, g)
    // 多维数组 解构赋值
    let arr2 = [11, [22, [33, 44]]]
    let [k, [l, [r, t]]] = arr2
    console.log(k, l, r, t)
    // 对象的解构赋值
    let obj = { name: "qianshu", "age": 16 }
    let { name: ht, age, sex = "女" } = { name: "qianshu", "age": 16 }//无序的属行集合
    //name:ht name要与obj中的key相同 ht为name的新名
    //:别名  =默认值
    console.log(ht, age, sex)
    //交换变量值
    // 传统办法
    let x = 1;
    let y = 2;
    let xy
    xy = x
    x = y
    y = xy
    console.log(x, y)
    // 解构赋值进行交换变量值，节省一个变量名，更简单
    [y, x] = [x, y]


    // 冒泡排序
    let array = [1, 4, 23, 4, 5, 66, 7, 8, 8, 9, 3, 35, 6, 6, 2]
    for (let i = 0; i < array.length; i++) {
        for (let j = 0; j < array.length; j++) {
            if (array[j] < array[j + 1]) {
                [array[j], array[j + 1]] = [array[j + 1], array[j]]
            }
        }
    }
    console.log(array)
    
</script>

</html>